package com.onpositive.page.pagerendering;

import com.onpositive.page.core.NamedLink;

public class AccountsManagementRenderer {
	
	public static final String SIGN_IN_LABEL = "Sign in";
	public static final String SIGN_OUT_LABEL = "Sign out";
	public static final String LOGIN_SUFFIX = ".login";
	
//	public static final String NICK_ATTR = "nick";
//	public static final String INP_ATTR = "button";
	
	private NamedLink loginLink;
	private String nickName;
	
	
	public AccountsManagementRenderer(String uri, String userNickName){
		String label = userNickName.length() > 0 ? SIGN_OUT_LABEL: SIGN_IN_LABEL;
		if(label.length() > 0){
			nickName = userNickName;
		}
		loginLink = new NamedLink(uri + LOGIN_SUFFIX,label);
	}
	
	public String getLoginLink(){
		StringBuilder sb = new StringBuilder();		
		sb.append("<table>");
		sb.append("<tr><td>");			
		sb.append(nickName);			
		sb.append("</td><td>");
		sb.append("<a ");
		sb.append(" href=\"" + loginLink.getUrl() +"\">" );
		sb.append(loginLink.getTitle());
		sb.append("</a>");
		sb.append("</td></tr>");
		sb.append("</table>");
		return sb.toString();
	}
	
}
